import DB
import json
import flask

class Service:
    def __init__(self):
        self.db = DB.DB()
    def get_books_short_info(self, args):
        '''获取所有单词表的信息

        Return:
        [(id, name) ...]'''
        ret = self.db.get_books_short_info()
        return json.dumps(ret)

    def get_lesson_content(self, args):
        book_id = args['book_id']
        lesson_type = args['lesson_type']
        lesson_id = args['lesson_id']
        ret = self.db.get_lesson_content(book_id, lesson_type, lesson_id)
        if ret == None:
            flask.abort(404)
        return json.dumps(ret)


    # def get_all_dc_idx_by_list_id(self, args):
    #     ret = self.db.get_all_dc_idx_by_list_id(args['list_id'])
    #     return json.dumps(ret)
        
    # def get_dc_info(self, args):
    #     ret = self.db.get_dc_by_ids(args['ids'].split(','))
    #     ret = map(int, ret)
    #     return json.dumps(ret)

    # def get_dc_info_by_list_id(self, args):
    #     ret = self.db.get_all_dc_idx_by_list_id(args['list_id'])
    #     ret = self.db.get_dc_by_ids(ret)
    #     return json.dumps(ret)
